<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>axios请求别名</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
    <h1>axios请求别名</h1>
    <button id="btnGet">发送查询get请求</button>
    <button id="btnPost">发送新增post请求</button>
    <button id="btnUpdate">发送更新update请求</button>
    <button id="btnDelete">发送删除delete请求</button>

    <script>
        const oBtnGet = document.getElementById('btnGet');
        const oBtnPost = document.getElementById('btnPost');
        const oBtnUpdate = document.getElementById('btnUpdate');
        const oBtnDelete = document.getElementById('btnDelete');

        oBtnGet.onclick = async function(){
            try{
                const re = await axios.get("/user",{
                    params: {
                        userId: "001"
                    }
                })
                console.log(re.data);
            }catch(e){
                console.log(e.message);
            }
        }

        oBtnPost.onclick = async function(){
            try{
                const re = await axios.post("/adduser",{
                    name: "韩立",
                    age: 15000,
                    sex: "男"
                })
                console.log(re.data);
            }catch(e){
                console.log(e.message);
            }
        }

        oBtnUpdate.onclick = async function(){
            try{
                const re = await axios.put("/updateuser",{
                    name: "韩立",
                    age: 15000,
                    Lv: "大乘"
                })
                console.log(re.data);
            }catch(e){
                console.log(e.message);
            }
        }

        oBtnDelete.onclick = async function(){
            try{
                const re = await axios.delete("/deleteuser",{
                    params: {
                        userId: "002"
                    }
                })
                console.log(re.data);
            }catch(e){
                console.log(e.message);
            }
        }
    </script>
</body>
</html>